import { ShapeFlags } from '@/shared/ShapeFlags'

export function createVNode(type, props?, children?) {
  const node = {
    type,
    props,
    children,
    el: null,
    shapeFlag: getShapeFlag(type)
  }
  if (typeof children === 'string') {
    node.shapeFlag = node.shapeFlag | ShapeFlags.TEXT_CHILDREN
  } else if (Array.isArray(children)) {
    node.shapeFlag = node.shapeFlag | ShapeFlags.ARRAY_CHILDREN
  }

  // slots 组件+children,object
  if (node.shapeFlag & ShapeFlags.STATEFULCOMPONENT) {
    if (typeof children === 'object') {
      node.shapeFlag = node.shapeFlag | ShapeFlags.SLOTS_CHILDREN
    }
  }
  return node
}

function getShapeFlag(type) {
  if (typeof type === 'string') {
    return ShapeFlags.ELEMENT
  } else {
    return ShapeFlags.STATEFULCOMPONENT
  }
}
